package com.backend.demo1.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisUtils {

    @Autowired
    private StringRedisTemplate redisTemplate;

    // 获取点赞数
    public int getLikeCount(String articleId) {
        String key = "article:like:" + articleId;
        String count = redisTemplate.opsForValue().get(key);
        return count == null ? 0 : Integer.parseInt(count);
    }

    // 增加点赞数
    public void incrementLike(String articleId) {
        String key = "article:like:" + articleId;
        redisTemplate.opsForValue().increment(key, 1);
    }
}